<?php
/**
 * Created by PhpStorm.
 * User: suruixiang
 * Date: 2017/10/16
 * Time: 下午1:41
 */
namespace app\api\controller;

use think\Config;
use think\Request;
use app\index\model\Channel;
use app\index\model\Visits;
use app\index\model\Courses;

class Skip extends Common
{
    public function index(Request $request)
    {
        $channel_id = $request->param('channel_id', 0, 'intval');
        if (!$channel_id) {
            return view('common/error', [
                'message' => '对不起，渠道不正确！'
            ]);
        }
        $channelModel = new Channel();
        $channel_info = $channelModel->getInfoByWhere([
            'id' => $channel_id,
        ]);
        if (!$channel_info || $channel_info['status'] == 2) {
            return view('common/error', [
                'message' => '对不起，渠道不正确！'
            ]);
        }
        $coursesModel = new Courses();
        $course_info = $coursesModel->getInfoByField('id', $channel_info->course_id, 'cps_is_del');
        if ($course_info->cps_is_del) {
            return view('common/error', [
                'message' => '对不起，课程不存在！'
            ]);
        }
        $visits = new Visits();
        $visits->addData($channel_info);

        $url = Config::get('config.cz_h5_link') . $channel_info->course_id . '&channel_id=' . $channel_id;
        $this->redirect($url);
    }
}